package com.xl6667.controller;

import com.xl6667.domain.ResponseResult;
import com.xl6667.domain.dto.AddUser;
import com.xl6667.domain.entity.User;
import com.xl6667.service.UserRoleService;
import com.xl6667.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("system/user")
public class userController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserRoleService userRoleService;

    /**
     * 查询所有用户信息
     * @param pageNum
     * @param pageSize
     * @param username
     * @param phonenumber
     * @param status
     * @return
     */
    @GetMapping("/list")
    public ResponseResult getUserList(Integer pageNum,Integer pageSize,String userName,String phonenumber,String status){
        return userService.getUserList(pageNum,pageSize,userName,phonenumber,status);
    }
    /**
     * 新增用户
     *
     */
    @PostMapping
    public ResponseResult addUser(@RequestBody AddUser addUser){
        return userRoleService.addUser(addUser);
    }

    /**
     * 修改回显
     */
    @GetMapping("/{id}")
    public ResponseResult getUserAndRole(@PathVariable Long id){
        return userRoleService.getUserAndRole(id);
    }
    @PutMapping
    public ResponseResult putUser(@RequestBody AddUser addUser){
        return userRoleService.putUser(addUser);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delUser(@PathVariable Long id){
        return userService.delUser(id);
    }

    @PutMapping("/changeStatus")
    public ResponseResult changeStatusUser(@RequestBody User user){
        return userService.changeStatusUser(user);
    }



}
